//===============================================================================
// Microsoft patterns & practices Enterprise Library Contribution
// Query Application Block
//===============================================================================

using System;
using System.ComponentModel;
using System.Drawing.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design;
using Microsoft.Practices.EnterpriseLibrary.Configuration.Design.Validation;
using EntLibContrib.Query.Commands;
using EntLibContrib.Query.Properties;

namespace EntLibContrib.Query.Configuration.Design
{
	/// <summary>
	/// Represents a custom service command. 
	/// </summary>
	[Image(typeof(ServiceCommandNode))]
	[SelectedImage(typeof(ServiceCommandNode))]
	public class ServiceCommandNode : CommandNode
	{
		#region Properties
		/// <summary>
		/// Gets or sets the <see cref="Type"/> that implements <see cref="ServiceCommand"/>.
		/// </summary>
		/// <value>
		/// The <see cref="Type"/> that implements <see cref="ServiceCommand"/>.
		/// </value>
		[Required]
		[Editor(typeof(TypeSelectorEditor), typeof(UITypeEditor))]
		[BaseType(typeof(ServiceCommand))]
		[QueryCategory("CategoryProvider")]
		[QueryDescription("ServiceCommandCommandTypeDescription")]
		public string CommandType
		{
			get { return base.CommandTypeName; }
			set { base.CommandTypeName = value; }
		}

		/// <summary>
		/// Gets a <see cref="CustomCommandData"/> configuration object using the node data.
		/// </summary>
		/// <value>
		/// A <see cref="CustomCommandData"/> configuration object using the node data.
		/// </value>
		[ReadOnly(true)]
		public override CustomCommandData CommandData
		{
			get { return new ServiceCustomCommandData(Name, base.CommandTypeName); }
		}
		#endregion

		#region Construction
		/// <summary>
		/// Initialize a new instance of the <see cref="ServiceCommandNode"/> class.
		/// </summary>
		public ServiceCommandNode()
			: this(new ServiceCustomCommandData(InternalResources.DefaultServiceCommandNodeName, string.Empty))
		{
		}

		/// <summary>
		/// Initialize a new instance of the <see cref="ServiceCommandNode"/> class with a <see cref="ServiceCustomCommandData"/> object.
		/// </summary>
		/// <param name="serviceCustomCommandData">The service custom command data.</param>
		public ServiceCommandNode(ServiceCustomCommandData serviceCustomCommandData)
		{
			if (serviceCustomCommandData == null)
				throw new ArgumentNullException("serviceCustomCommandData");

			Rename(serviceCustomCommandData.Name);
			base.CommandTypeName = serviceCustomCommandData.CommandTypeName;
		}
		#endregion
	}
}